package com.group.elmboot.controller;

import com.group.elmboot.po.Transition;
import com.group.elmboot.po.Wallet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.group.elmboot.service.WalletService;

import java.util.List;
@RefreshScope//开启动态刷新
@RestController
@RequestMapping("/WalletController")
public class WalletController {

	@Autowired
    private WalletService walletService;
	
	@GetMapping("/createWallet/{userId}")
    public int createWallet(@PathVariable("userId") String userId) throws Exception{
        return walletService.createWallet(userId);
    }
	
	//third-partyPayment:0：使用钱包支付；1：使用第三方支付，支付成功过后再调用该接口
	@GetMapping("/upgradeVIPWallet/{userId}/{VIPmonths}/{third_partyPayment}")
    public int upgradeVIPWallet(@PathVariable String userId,@PathVariable int VIPmonths,@PathVariable int third_partyPayment) throws Exception{
        return walletService.upgradeVIPWallet(userId,VIPmonths,third_partyPayment);
    }
	
	@GetMapping("/payByWallet/{orderId}/{redPacket}")
    public int payByWallet(@PathVariable int orderId, @PathVariable String redPacket) throws Exception{
        return walletService.payByWallet(orderId,redPacket);
    }
	
	@GetMapping("/confirmReceipt/{orderId}")
	public int confirmReceipt(@PathVariable int orderId) throws Exception{
        return walletService.confirmReceipt(orderId);
    }
	
	@GetMapping("/draw/{userId}/{amount}")
	public int draw(@PathVariable String userId,@PathVariable String amount) throws Exception{
        return walletService.draw(userId,amount);
    }
	
	@GetMapping("/recharge/{userId}/{amount}")
	public int recharge(@PathVariable String userId,@PathVariable String amount) throws Exception{
        return walletService.recharge(userId,amount);
    }
	
	@GetMapping("/getWalletInfoById/{userId}")
	public Wallet getWalletInfoById(@PathVariable String userId) {
		return walletService.selectById(userId);
	}

    @GetMapping("/listTransitionsById/{userId}")
    public List<Transition> listTransitionById(@PathVariable("userId") String userId){
        return walletService.listTransitionById(userId);
    }

}